from functools import wraps
from flask import redirect,url_for,g

def check(permission):
    def inner(func):
        @wraps(func)
        def h_inner(*args,**kwargs):
            if g.user.has_permission(permission):
                return func(*args,**kwargs)
            else:
                return redirect(url_for("cms.cms_index"))
        return h_inner
    return inner